﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.ComponentModel.Composition;
using VanGuideWP7.ViewModel;
using GalaSoft.MvvmLight.Messaging;
using VanGuideWP7.Model;

namespace VanGuideWP7.View
{
    public partial class DetailsAddComment : PhoneApplicationPage
    {
        public DetailsAddComment()
        {
            InitializeComponent();
            //init composition
            CompositionInitializer.SatisfyImports(this);
            DataContext = this.DetailsAddCommentViewModel;

        }

        [Import(typeof(DetailsAddCommentViewModel))]
        public DetailsAddCommentViewModel DetailsAddCommentViewModel { get; set; }

        private void btnSave_Click(object sender, EventArgs e)
        {
            Messenger.Default.Register<bool>(this, MessageTokens.CommentAdded, OnCommentAdded);
            DetailsAddCommentViewModel.AddNewComment.Execute(tbTag.Text);
        }

        private void OnCommentAdded(bool sucess)
        {
            Messenger.Default.Unregister<bool>(this, OnCommentAdded);
            Dispatcher.BeginInvoke(() => { NavigationService.GoBack(); });
        }
    }
}